package demoxsgl_300.com.gouwu1500.http;

import android.util.Log;

import java.util.HashMap;
import java.util.Map;

import demoxsgl_300.com.gouwu1500.base.MyApplication;
import demoxsgl_300.com.gouwu1500.utils.JSONUtils;
import demoxsgl_300.com.gouwu1500.utils.SpfUtils;
import demoxsgl_300.com.gouwu1500.zhi.Content;


/**
 * Created by 他的猫 on 2017/5/10.
 */

public class API {


    /**
     * 数据列表查询
     *
     * @param
     * @param handler
     */
    public static void DiBengTJ(
            String startDate,
            String endDate, String water_zhanid, Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();

        map.put("startDate", startDate);
        map.put("endDate", endDate);
        map.put("water_zhanid", water_zhanid);
        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "数据列表查询" + jg2);
        Log.e("API2", getBase() + "TCP_BB/Devices/querylist");
        Okhttp.post(getBase() + "TCP_Water/Devices/querylist", map, handler);

    }

    //    http://39.98.45.185:5165
    public static String getBase() {
        String ip = (String) SpfUtils.get(MyApplication.getInstance(), "ip", "39.98.45.185");
        String url = "http://" + ip + ":5165/";
        return url;
    }

    /**
     * 登录
     *
     * @param user_phone
     * @param user_password
     * @param handler
     */
    public static void Login(
            String user_phone,
            String user_password, Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();

        map.put("user_phone", user_phone);
        map.put("user_password", user_password);

        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "登录" + jg2);

        Okhttp.get(getBase() + "login", map, handler);

    }

    /**
     * 注册
     *
     * @param user_phone
     * @param user_password
     * @param handler
     */
    public static void Registuser(
            String user_phone,
            String user_password, Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("user_phone", user_phone);
        map.put("user_password", user_password);
        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "注册" + jg2);
        Okhttp.get(getBase() + "registuser", map, handler);

    }

    /**
     * 舌头识别接口
     * @param location
     * @param handler
     */
    public static void tongue(
            String location,
            Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("location", location);
        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "用户登录后根据手机号展示问诊档案" + jg2);
        Okhttp.get(getBase() + "tongue", map, handler);

    }

    /**
     * 3.根据查询的主诉返回发作特点，性质，诱因和兼症
     *
     * @param disease_name
     * @param handler
     */
    public static void inquisition(
            String disease_name,
            Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("disease_name", disease_name);
        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "据查询的主诉返回发作特点，性质，诱因和兼症" + jg2);
        Okhttp.get(getBase() + "inquisition", map, handler);

    }

    /**
     * 4.根据用户的舌头类型和选择的症状返回最终结果
     *
     * @param disease_name
     * @param handler
     */
    public static void zhen(
            String disease_name,
            String chars,
            String zhenzhang,
            Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("disease_name", disease_name);
        map.put("char", chars);
        map.put("zhenzhang", zhenzhang);
        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "根据用户的舌头类型和选择的症状返回最终结果" + jg2);
        Okhttp.get(getBase() + "zhen", map, handler);

    }


    /**
     * 5.根据用户的舌头类型和选择的症状返回最终结果
     *
     * @param disease_name
     * @param handler
     */
    public static void insertresult(
            String user_phone,
            String sex,
            String old,

            String tongue,
            String disease_name,
            String symptom,

            String pharmacy,
            String dialectical,
            String treat,

            String pathogeny,
            String exercise_therapy,
            String food_treatment,


            Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("user_phone", user_phone);
        map.put("sex", sex);
        map.put("old", old);

        map.put("tongue", tongue);
        map.put("disease_name", disease_name);
        map.put("symptom", symptom);

        map.put("pharmacy", pharmacy);
        map.put("dialectical", dialectical);
        map.put("treat", treat);


        map.put("pathogeny", pathogeny);
        map.put("exercise_therapy", exercise_therapy);
        map.put("food_treatment", food_treatment);
        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "递交数据" + jg2);
        Okhttp.get(getBase() + "insertresult", map, handler);

    }
    /**
     * 6.用户登录后根据手机号展示问诊档案
     *
     * @param user_phone
     * @param handler
     */
    public static void historyrecord(
            String user_phone,
            Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("user_phone", user_phone);
        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "用户登录后根据手机号展示问诊档案" + jg2);
        Okhttp.get(getBase() + "historyrecord", map, handler);

    }

    /**
     * +
     * 7.根据用户手机号和问诊时间查询具体的档案
     *
     * @param user_phone
     * @param wztime
     * @param handler
     */
    public static void searchresult(
            String user_phone, String wztime,
            Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("user_phone", user_phone);
        map.put("wztime", wztime);
        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "根据用户手机号和问诊时间查询具体的档案" + jg2);
        Okhttp.get(getBase() + "searchresult", map, handler);

    }


    /**
     * +
     * 7.递交建议
     *
     * @param user_phone
     * @param
     * @param handler
     */
    public static void submission(
             String value,
            Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("user_phone", Content.user_password);
        map.put("value", value);
        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "根据用户手机号和问诊时间查询具体的档案" + jg2);
        Okhttp.get(getBase() + "submission", map, handler);

    }
}
